<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 huan $
*/
defined('BY_JYA') or exit('error');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();

if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['code1'])){
		$params['code1']=trim($_RQ['code1']);
		$return['params']['code1']=$params['code1'];
	}
	$parameter=array('params'=>$params,'limit'=>array($pindex,$psize),'fields'=>$fields,'orderby'=>'id desc');
	$list=$this->get_list('hexiao',$parameter,$total);
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['gameName']=pdo_getcolumn('jy_h5game_reply',array('id'=>$item['rid']),'title');
			$item['gameName']=pdo_getcolumn('jy_h5game_award',array('id'=>$item['awardid']),'award');
			$item['prizeType']=pdo_getcolumn('jy_h5game_award',array('id'=>$item['awardid']),'prizeType');
		}
	}
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['htmls']=array (
		  'type' => 'list',
		  'tabs' =>array(
		    array ('op' => 'list','title' => '核销列表'),
		  ),
		  'list' => array (
		    'data' => 'list','delall' => false,'del_one'=>false,'edit'=>false,
			'tip'=>'这里只显示线下兑换商品记录：实物兑换，实物发货等',
		    'list' =>array(
		      array('type' => 'time','name' => 'createtime','title' => '核销时间' ),
			  array('name'=>'member','title'=>'获奖者','type'=>'member'),
		      array('name' => 'code1','type' => 'string','title' => '兑换码',),
		      array('name' => 'rid','type' => 'string','title' => '活动编号',),
		      array('name' => 'gameName','type' => 'string','title' => '活动名称'),
			  array('name' => 'consumeType','type' => 'radio','options'=>'consumeType','title' => '核销方式'),   
			  array('name' => 'award','type' => 'string','title' => '奖品'),   	
			  array('name' => 'prizeType','type' => 'radio','options'=>'prizeType','title' => '奖品类型'), 
			  array ('name' => 'note','type' => 'string','title' => '备注'),   
		    )),'search' =>array(
				  array ('name' => 'code1','width'=>'15','type' => 'string','title' => '劵码'),
			 ),
	);
	$return['consumeType']=$this->consumeType;
	$return['prizeType']=$this->prizeType;
	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=$this->get('category',array('id'=>$id));

	}else{
		$item=array();
	}
	$return['item']=$item;
	$return['htmls']=array (
  'type' => 'edit',
  'post' => 'post',
  'edit_tab' => '商品分类',
  'edits' => 
  array (
    0 => 
    array (
      'title' => '商品分类',
      'list' => 
      array (
        0 => 
        array (
          'name' => 'displayorder',
          'type' => 'string',
          'title' => '排序',
        ),
        1 => 
        array (
          'name' => 'name',
          'type' => 'string',
          'title' => '分类名称',
        ),
        2 => 
        array (
          'name' => 'thumb',
          'type' => 'image',
          'title' => '分类图片',
        ),
        3 => 
        array (
          'name' => 'description',
          'type' => 'text',
          'title' => '分类描述',
        ),
        4 => 
        array (
          'name' => 'isrecommand',
          'type' => 'switch',
          'title' => '是否推荐',
        ),
        5 => 
        array (
          'name' => 'enabled',
          'type' => 'switch',
          'title' => '是否显示',
        ),
      ),
    ),
  ),
);

	exi($return);
}
if($_RQ['op']=='post'){
	$post=get_postdata();
	$data=array_fields(array('displayorder','name','thumb','description','isrecommand','enabled',),$post);

	$id=intval($post['id']);
	if($id){
		$this->update('category',$data,array('id'=>$id));
		exi('修改商品分类表成功！');
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=TIMESTAMP;
		$this->insert('category',$data);
		exi('新增商品分类表成功！');
	}
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if($id){
		$this->delete('hexiao',array('id'=>$id));
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				$this->delete('hexiao',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
}